﻿package com.vicentediaz.data
{
    import com.vicentediaz.data.events.*;
    import flash.events.*;
    import flash.net.*;

    public class Config extends EventDispatcher
    {
        private var _loaded:Boolean = false;
        private var PATH:String = "xml/config.xml";
        private var _xml:XML;
        private static var instance:Config;

        public function Config(param1:IEventDispatcher = null)
        {
            super(param1);
            var _loc_2:* = new URLLoader(new URLRequest(this.PATH));
            _loc_2.addEventListener(Event.COMPLETE, this.onConfigLoaded, false, 0, true);
            return;
        }// end function

        private function onConfigLoaded(param1:Event) : void
        {
            this._xml = XML(param1.target.data);
            dispatchEvent(new ConfigEvent(ConfigEvent.CONFIG_LOADED));
            this._loaded = true;
            return;
        }// end function

        public function get xml() : XML
        {
            return this._xml;
        }// end function

        public function getByValue(param1:String) : String
        {
            var value:* = param1;
            if (this.xml)
            {
                var _loc_4:int;
                var _loc_5:* = this._xml.data;
                var _loc_3:* = new XMLList("");
                for each (_loc_6 in _loc_5)
                {
                    // label
                    var _loc_7:* = _loc_5[_loc_4];
                    with (_loc_5[_loc_4])
                    {
                        if (@type == value)
                        {
                            _loc_3[_loc_4] = _loc_6;
                        }// end if
                    }// end with
                }// end of for each ... in
                return _loc_3;
            }
            else
            {
            }// end else if
            throw new Error("No se ha cargado todav?a el XML de configuraci?n");
        }// end function

        public function get loaded() : Boolean
        {
            return this._loaded;
        }// end function

        public static function getInstance() : Config
        {
            instance = instance ? (instance) : (new Config);
            return instance;
        }// end function

    }
}
